package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JComboBox;
import javax.swing.JTextArea;

public class PoliceListen2 implements ItemListener{

	JComboBox<String> choice;
	JTextArea textArea; 

	public void setJComboBox(JComboBox<String> choice) {
		this.choice = choice;
	}
	
	public void setJTextArea(JTextArea textArea) {
		this.textArea = textArea;
	}
	
	@Override
	public void itemStateChanged(ItemEvent e) {
		textArea.setText(null);
		String fileName = choice.getSelectedItem().toString();
		File file = new File("C:\\Users\\lenovo\\git\\201734020124_wu_jiaxian\\201734020124吴嘉贤\\src\\cn\\edu\\scau\\cmi\\wujiaxian\\exercise11\\" + fileName);
		BufferedReader in = null;
		try {
			in = new BufferedReader(new FileReader(file));
			String s = null;
			while ((s = in.readLine()) != null) {
				textArea.append(s + "\n");
			}
			in.close();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
	
}
